<?php
$tableProduct = "product";


$week=$_REQUEST["week"];

if($week=="next")
{
    $week_term=7;
}
else
{
    $week_term=0;
}


$day_start_1=date("d",time())-date("w")+1+$week_term;

$day_start_2=$day_start_1+1;
if($day_start_2>date('t',time()))
{$day_start_2=$day_start_2-date('t',time());}

$day_start_3=$day_start_1+2;
if($day_start_3>date('t',time()))
{$day_start_3=$day_start_3-date('t',time());}

  $day_start_4=$day_start_1+3;
if($day_start_4>date('t',time()))
{$day_start_4=$day_start_4-date('t',time());}

  $day_start_5=$day_start_1+4;
if($day_start_5>date('t',time()))
{$day_start_5=$day_start_5-date('t',time());}

  $day_start_6=$day_start_1+5;
if($day_start_6>date('t',time()))
{$day_start_2=$day_start_6-date('t',time());}

  $day_start_7=$day_start_1+6;
if($day_start_7>date('t',time()))
{$day_start_7=$day_start_7-date('t',time());}





$query = mysql_query("select count(product_id) from $tableProduct where
week = '$day_start_1' or
week = '$day_start_2' or
week = '$day_start_3' or
week = '$day_start_4' or
week = '$day_start_5' or
week = '$day_start_6' or
week = '$day_start_7'


 ");
$sum = mysql_result($query, 0);

$result = mysql_query("select * from  $tableProduct where
week = '$day_start_1' or
week = '$day_start_2' or
week = '$day_start_3' or
week = '$day_start_4' or
week = '$day_start_5' or
week = '$day_start_6' or
week = '$day_start_7'

order by
week,at");

while ($row = mysql_fetch_array($result)) {
    $product_names[]   = $row['product_name'];
    $product_price[]  = $row['price'];
    $product_week[]   = $row['week'];
    $product_at[]     = $row['at'];
    $product_ids[]     = $row['product_id'];
}


?>